package test3

import scala.collection.mutable.ListBuffer

object ListGAojie {
  def main(args: Array[String]): Unit = {
    var l =(1 to 10)
    var list=ListBuffer[Int]();
    l.foreach(x=>{
       list.append(x)
    })
    println(list)
    //list.foreach(println)
    //
    var l2=list.map(x=>{
       x*10;
    });
   // println(l2)
    l2.foreach(a=>{
      println(a)
    })
    println(">>>>>>>>>>>>>")
    val l3 = list.filter(_%5==0)
    l3.foreach(x=>{
      print(x+" ")
      if(x%20==0)
        println()
    })
    println()
    val total = list.fold(9)(_+_)
    println(total);

    val total2 = list.foldRight(0)(_-_)
    println(total2);
    val total3 = list.foldLeft(0)(_-_)
    println(total3);
    println(">>>>>>>>>>>>>>>>>>>>>>")
    val total4 = list.reduce(_+_);
    println(total4);
    val total5 = list.reduceLeft(_-_);//1-2-3...10
    println(total5);
    val total6 = list.reduceRight(_-_);// 7-(8-(9-10))...
    println(total6);
  }
}
